<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.hkw.model.Student" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: 12244
  Date: 2020/8/29
  Time: 13:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>班级列表</title>
    <link rel="stylesheet" href="./css/bootstrap.min.css">
</head>
<body>
<%--点击按钮，弹出模态框--%>
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
    添加
</button>
&nbsp;&nbsp;&nbsp;
<a href="studentlist" class="btn btn-primary btn-lg active" role="button">学生管理</a>
&nbsp;&nbsp;&nbsp;
<a class="btn btn-default" href="outLogin" role="button">退出</a>
<form class="form-inline" action="searchClassRoom" method="post">
    <div class="form-group">
        <label for="classname2">班级名称</label>
        <input type="text" class="form-control" id="classname2" placeholder="ClassName" name="name">
    </div>
    <div class="form-group">
        <label for="grade2">年级</label>
        <input type="text" class="form-control" id="grade2" placeholder="grade" name="grade">
    </div>
    <div class="form-group">
        <label for="teaname2">班主任名称</label>
        <input type="text" class="form-control" id="teaname2" placeholder="TeacherName" name="classTeaName">
    </div>
    <button type="submit" class="btn btn-default">搜索</button>
</form>
<%--表格标签显示所有学生信息--%>
<table class="table table-hover">
    <tr>
        <th>编号</th>
        <th>班级名称</th>
        <th>年级</th>
        <th>班主任</th>
        <th>口号</th>
        <th>人数</th>
        <th>修改</th>
        <th>删除</th>
    </tr>
    <c:forEach var="v" items="${classList}">
    <tr>
        <td>${v.id}</td>
        <td>${v.name}</td>
        <td>${v.grade}</td>
        <td>${v.classTeaName}</td>
        <td>${v.slogan}</td>
        <td>${v.number}</td>
        <td><a href="findClassRoom?id=${v.id}">修改</a></td>
        <td><a href="delClassRoom?id=${v.id}">删除</a></td>
    </tr>
    </c:forEach>
<%--    <%--%>
<%--        }--%>
<%--    %>--%>
</table>
<%--分页样式--%>
<div align="center">
<nav aria-label="Page navigation">
    <ul class="pagination pagination-lg">
        <li>
            <a href="classRoomList?nowpage=${reaPage - 1}" aria-label="Previous" id="left">
                <span aria-hidden="true">&laquo;</span>
            </a>
        </li>
<%--        <%=(Integer)request.getAttribute("reaPage")%>--%>
        <li><a href="#">${reaPage}</a></li>
        <li>
            <a href="classRoomList?nowpage=${reaPage + 1}" aria-label="Next" id="right">
                <span aria-hidden="true">&raquo;</span>
            </a>
        </li>
    </ul>
</nav>
</div>
<%--模态框，用来添加班级信息--%>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">添加班级</h4>
            </div>
            <div class="modal-body">
                <form action="addClassRoom" method="post" onsubmit="return check()">
                    <div class="form-group">
                        <label for="classname1">班级名称</label>
                        <input type="text" class="form-control" id="classname1" placeholder="classname" name="classname">
                    </div>
                    <div class="form-group">
                        <label for="grade1">年级</label>
                        <input type="text" id="grade1" class="form-control" placeholder="grade" name="grade">
                    </div>
                    <div class="form-group">
                        <label for="classTeaName1">班主任名称</label>
                        <input type="text" class="form-control" id="classTeaName1" placeholder="classTeaName" name="classTeaName">
                    </div>
                    <div class="form-group">
                        <label for="solgan1">口号</label>
                        <input type="text" class="form-control" id="solgan1" placeholder="solgan" name="slogan">
                    </div>
                    <button type="submit" class="btn btn-default" id="addClassRoom">添加</button>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
<%--修改成功，下面标签里有值--%>
<label hidden id="delClassOk"><%=request.getAttribute("delClassOk")%></label>
<%--修改失败，下面标签里有值--%>
<label hidden id="delClassFail"><%=request.getAttribute("delClassFail")%></label>
<%--查找失败，下面标签里有值--%>
<label hidden id="searcherror"><%=request.getAttribute("searcherror")%></label>
</body>
<script src="./js/jquery-3.3.1.min.js"></script>
<script src="./js/bootstrap.min.js"></script>
<script>
    //校验方法
    function check(){
        if($("#classname1").val()==null||$("#classname1").val().trim()==""){
            alert("班级名称不能为空!");
            return false;
        }else if($("#grade1").val()==null||$("#grade1").val().trim()==""){
            alert("年级不能为空!");
            return false;
        }else if($("#classTeaName1").val()==null||$("#classTeaName1").val().trim()==""){
            alert("班主任名称不能为空!");
            return false;
        }else if($("#solgan1").val()==null||$("#solgan1").val().trim()==""){
            alert("口号不能为空!");
            return false;
        }
        return true;
    }
    //修改成功弹框提醒
    $(function(){
        var value = $("#delClassOk").html();
        if(value != "null"){
            alert(value);
        }
    });
    //修改失败弹框提醒
    $(function(){
        var value = $("#delClassFail").html();
        if(value != "null"){
            alert(value);
        }
    });
    //查找成功弹框提醒
    $(function(){
        var value = $("#searcherror").html();
        if(value != "null"){
            alert(value);
        }
    });
</script>
</html>
